import 'package:flutter_test/flutter_test.dart';
import 'package:figo_player_plugin/figo_player_plugin.dart';

void main() {
  group('FigoPlayerPlugin', () {
    late FigoPlayerController controller;
    
    setUp(() {
      controller = FigoPlayerController();
    });
    
    tearDown(() {
      controller.dispose();
    });
    
    test('should create controller', () {
      expect(controller, isNotNull);
      expect(controller.state, PlayerState.idle);
    });
    
    test('should have correct initial state', () {
      expect(controller.isPlaying, isFalse);
      expect(controller.isPaused, isFalse);
      expect(controller.isStopped, isTrue);
    });
    
    test('should handle volume control', () async {
      await controller.setVolume(0.5);
      // 注意：这里只是测试方法调用，实际音量控制需要平台实现
    });
    
    test('should handle hardware decode setting', () async {
      await controller.setHardwareDecode(true);
      // 注意：这里只是测试方法调用，实际硬件解码需要平台实现
    });
    
    test('should handle battery optimization setting', () async {
      await controller.setBatteryOptimization(true);
      // 注意：这里只是测试方法调用，实际省电模式需要平台实现
    });
    
    test('should handle memory limit setting', () async {
      await controller.setMemoryLimit(100);
      // 注意：这里只是测试方法调用，实际内存限制需要平台实现
    });
  });
  
  group('PlayerState', () {
    test('should have correct display names', () {
      expect(PlayerState.idle.displayName, '空闲');
      expect(PlayerState.loading.displayName, '加载中');
      expect(PlayerState.playing.displayName, '播放中');
      expect(PlayerState.paused.displayName, '已暂停');
      expect(PlayerState.stopped.displayName, '已停止');
      expect(PlayerState.error.displayName, '错误');
    });
  });
  
  group('MediaInfo', () {
    test('should create from map', () {
      final map = {
        'title': 'Test Video',
        'artist': 'Test Artist',
        'album': 'Test Album',
        'duration': 120000,
        'width': 1920,
        'height': 1080,
        'frameRate': 30.0,
        'codec': 'h264',
        'bitrate': 2000000,
      };
      
      final mediaInfo = MediaInfo.fromMap(map);
      expect(mediaInfo.title, 'Test Video');
      expect(mediaInfo.artist, 'Test Artist');
      expect(mediaInfo.album, 'Test Album');
      expect(mediaInfo.duration.inMilliseconds, 120000);
      expect(mediaInfo.width, 1920);
      expect(mediaInfo.height, 1080);
      expect(mediaInfo.frameRate, 30.0);
      expect(mediaInfo.codec, 'h264');
      expect(mediaInfo.bitrate, 2000000);
    });
    
    test('should convert to map', () {
      const mediaInfo = MediaInfo(
        title: 'Test Video',
        artist: 'Test Artist',
        album: 'Test Album',
        duration: Duration(milliseconds: 120000),
        width: 1920,
        height: 1080,
        frameRate: 30.0,
        codec: 'h264',
        bitrate: 2000000,
      );
      
      final map = mediaInfo.toMap();
      expect(map['title'], 'Test Video');
      expect(map['artist'], 'Test Artist');
      expect(map['album'], 'Test Album');
      expect(map['duration'], 120000);
      expect(map['width'], 1920);
      expect(map['height'], 1080);
      expect(map['frameRate'], 30.0);
      expect(map['codec'], 'h264');
      expect(map['bitrate'], 2000000);
    });
  });
  
  group('PlayerConfig', () {
    test('should create default config', () {
      const config = PlayerConfig.defaultConfig();
      expect(config.hardwareDecode, isTrue);
      expect(config.batteryOptimization, isFalse);
      expect(config.memoryLimitMB, 100);
      expect(config.maxFrameRate, 60);
      expect(config.quality, 100);
      expect(config.lowLatency, isFalse);
    });
    
    test('should create battery optimized config', () {
      const config = PlayerConfig.batteryOptimized();
      expect(config.hardwareDecode, isFalse);
      expect(config.batteryOptimization, isTrue);
      expect(config.memoryLimitMB, 50);
      expect(config.maxFrameRate, 24);
      expect(config.quality, 80);
    });
    
    test('should create high quality config', () {
      const config = PlayerConfig.highQuality();
      expect(config.hardwareDecode, isTrue);
      expect(config.batteryOptimization, isFalse);
      expect(config.memoryLimitMB, 200);
      expect(config.maxFrameRate, 60);
      expect(config.quality, 100);
    });
    
    test('should convert to map', () {
      const config = PlayerConfig(
        hardwareDecode: true,
        batteryOptimization: false,
        memoryLimitMB: 150,
        maxFrameRate: 30,
        quality: 90,
        lowLatency: true,
      );
      
      final map = config.toMap();
      expect(map['hardwareDecode'], isTrue);
      expect(map['batteryOptimization'], isFalse);
      expect(map['memoryLimitMB'], 150);
      expect(map['maxFrameRate'], 30);
      expect(map['quality'], 90);
      expect(map['lowLatency'], isTrue);
    });
  });
}